
import java.util.Deque;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;

public class l20有效括号 {
    public static void main(String[] args) {
        isValid("[");
    }
    public static void isValid(String s ) {
        Map<Character, Character> mapping = new HashMap<>();
        mapping.put(')', '(');
        mapping.put('}', '{');
        mapping.put(']', '[');
        Deque<Character> stack = new LinkedList<>();
        for(int i =0;i<s.length();i++ ) {
            char tmp = s.charAt(i);
            if(mapping.containsValue(tmp)) {
                stack.push(tmp);
            }else {
                if(stack.isEmpty()) {
                    System.out.println("false");
                    return;
                }
                if(stack.pop()!=mapping.get(tmp)) {
                    System.out.println("false");
                    return;
                }
            }
        }

        System.out.println("true");


    }

}
